package com.physics.mps.module.task.sub;

import com.physics.mps.common.util.MinioUtil;
import com.physics.mps.entity.vo.ResponseResult;
import com.physics.mps.entity.vo.SubTaskQueryVo;
import com.physics.mps.entity.vo.SubTaskVo;
import com.physics.mps.module.task.vo.TestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

/**
 * @author mcsoft
 * @date 2023/9/15 10:02
 * @description 子任务接口
 */
@Api(tags = "任务中心-子任务")
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/subtask")
@Log4j2
public class SubTaskController {


    private final SubTaskService subTaskService;
    private final MinioUtil minioUtil;

    @ApiOperation(value = "创建子任务")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/addSubTask")
    public ResponseResult addSubTask(@RequestBody SubTaskVo subTaskVo) {
        return ResponseResult.success(subTaskService.increase(subTaskVo), null);
    }

    @ApiOperation(value = "分页查询子任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true),
            @ApiImplicitParam(paramType = "path", name = "current", value = "当前页", dataType = "Integer", required = true),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页数量", dataType = "Integer", required = true),
    })
    @PostMapping("/selectAppParamTree/{current}/{size}")
    public ResponseResult selectAppParamTree(@PathVariable("current") int current,
                                             @PathVariable("size") int size,
                                             @RequestBody SubTaskQueryVo subTaskQueryVo) {
        return ResponseResult.success(subTaskService.selectTask(current, size, subTaskQueryVo));
    }


    @ApiOperation(value = "删除子任务")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true),
            @ApiImplicitParam(paramType = "path", name = "id", value = "子任务ID", dataType = "String", required = true),
    })
    @PostMapping("/deleteSubTask/{id}")
    public ResponseResult deleteSubTask(@PathVariable("id") String id) {
        subTaskService.deleteSubTask(id);
        return ResponseResult.success();
    }


    @ApiOperation(value = "查询子任务")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true),
            @ApiImplicitParam(paramType = "path", name = "id", value = "子任务ID", dataType = "String", required = true),
    })
    @PostMapping("/getSubTask/{id}")
    public ResponseResult getSubTask(@PathVariable("id") String id) {
        return ResponseResult.success(subTaskService.getSubTask(id));
    }

    @ApiOperation(value = "统计仿真情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/getNumber")
    public ResponseResult getNumber() {
        return ResponseResult.success(subTaskService.getNumber());
    }

    @ApiOperation(value = "统计当前节点任务情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/getThreadPoolStatus")
    public ResponseResult getThreadPoolStatus() {
        return ResponseResult.success(subTaskService.getThreadPoolStatus());
    }

    @ApiOperation(value = "test")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/test")
    public ResponseResult test(@RequestBody TestVo testVo) {
        log.info("filename===={}", testVo.getFileName());
        log.info("objectName===={}", testVo.getObjectName());
        return ResponseResult.success(
                minioUtil.upload(testVo.getFileName(), "simulation",
                        testVo.getObjectName()
                ));
    }

}
